#!/bin/bash  
 
##
#[1-9][0-9]{4,}
# Only 1 parameter !  
if [ $# != 2 ];then  
    echo " Usage: .\read.sh filename!";  
    exit  
fi  
  
# check the file !  
if ! [ -f $1 ];then  
    echo "file does not exist!"  
    exit  
elif ! [ -r $1 ];then  
    echo "file can not be read !"  
    exit  
fi  


echo "enter continue"
# PRESS ANY KEY TO CONTITUE !  
read -p "begin to read $1 "  

#{
#    "allowlist": [
#        {
#            "qq": "123",
#            "imei": "456"
#        }
#    ]
#}

jsonHead="{
    \"allowlist\": [
"
jsonFooter="
    ]
}"

# set IFS="\n" , read $1 file per line !  
IFS="  
"  
  
# i is the line number  
i=1  
for line in `cat $1`  
do

    qq=$(echo $line | cut -d"," -f1)
    imei=$(echo $line | cut -d"," -f2)
grep $qq $2 >/dev/null
if [ $? -eq 0 ]; then
    cline="        {\"qq\": \"$qq\",\"imei\": \"$imei\"},"
    content=$content$cline
else
    echo "blackqq:"$qq >> blacklist.txt
fi

    let "i=$i+1"  
done  
 
json=$jsonHead$content$jsonFooter
echo $json > z17s.json

echo "Finished reading file by line ! "  
